home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Pascal / Utilities / MandelNet / helpBox.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-14  |  6.9 KB  |  288 lines  |  [TEXT/KAHL]

  1. #define NULL 0L
  2.  
  3.  
  4. pascal void HelpScrollProc(theControl, theCode)
  5. ControlHandle    theControl;int    theCode;
  6. {
  7. int            scrollAmt,height;
  8. int            controlMax,controlMin,controlVal;
  9. TEHandle    whichTEH;
  10.  
  11.     whichTEH = (TEHandle) GetCRefCon(theControl);
  12.     
  13.     if (!whichTEH || !(*whichTEH))
  14.         return;
  15.     
  16.     controlMax = GetCtlMax(theControl);
  17.     controlMin = GetCtlMin(theControl);
  18.     controlVal = GetCtlValue(theControl);
  19.     
  20.     switch (theCode) 
  21.     {
  22.         case inUpButton:
  23.             if (controlVal > controlMin)
  24.             {
  25.                 SetCtlValue(theControl,controlVal-1);
  26.                 
  27.                 TEScroll(0,TEGetHeight(controlVal-1,controlVal-1,whichTEH),whichTEH);
  28.             }
  29.             
  30.             break;
  31.             
  32.         case inDownButton: 
  33.             if (controlVal < controlMax)
  34.             {
  35.                 SetCtlValue(theControl,controlVal+1);
  36.                 
  37.                 TEScroll(0,-TEGetHeight(controlVal,controlVal,whichTEH),whichTEH);
  38.             }
  39.             
  40.             break;
  41.  
  42.         case inPageUp: 
  43.             if (controlVal > controlMin)
  44.             {
  45.                 scrollAmt = 1;
  46.                 height = (**whichTEH).viewRect.bottom - (**whichTEH).viewRect.top;
  47.                 
  48.                 while (controlVal-scrollAmt>controlMin && TEGetHeight(controlVal-scrollAmt,controlVal-1,whichTEH)<height)
  49.                     scrollAmt++;
  50.                 
  51.                 if (scrollAmt>1  && TEGetHeight(controlVal-scrollAmt,controlVal-1,whichTEH)>height)
  52.                     scrollAmt--;
  53.                 
  54.                 SetCtlValue(theControl,controlVal-scrollAmt);
  55.                 
  56.                 TEScroll(0,TEGetHeight(controlVal-scrollAmt,controlVal-1,whichTEH),whichTEH);
  57.             }
  58.             
  59.             break;
  60.  
  61.         case inPageDown: 
  62.             if (controlVal < controlMax)
  63.             {
  64.                 scrollAmt = 1;
  65.                 height = (**whichTEH).viewRect.bottom - (**whichTEH).viewRect.top;
  66.                 
  67.                 while (controlVal+scrollAmt<controlMax && TEGetHeight(controlVal,controlVal+scrollAmt-1,whichTEH)<height)
  68.                     scrollAmt++;
  69.                 
  70.                 if (scrollAmt>1  && TEGetHeight(controlVal,controlVal+scrollAmt-1,whichTEH)>height)
  71.                     scrollAmt--;
  72.                 
  73.                 SetCtlValue(theControl,controlVal+scrollAmt);
  74.                 
  75.                 TEScroll(0,-TEGetHeight(controlVal,controlVal+scrollAmt-1,whichTEH),whichTEH);
  76.             }
  77.             
  78.             break;
  79.     }
  80. }
  81.  
  82.  
  83.  
  84. DoHelpBox(helpResWIND,helpResTEXT,helpResSTYL)
  85. int        helpResWIND,helpResTEXT,helpResSTYL;
  86. {
  87. GrafPtr            oldPort;
  88. WindowPtr        helpWPtr;
  89. TEHandle        helpTEH;
  90. Rect            destRect,viewRect,vScrollRect,doneRect;
  91. Handle            helpText,helpStyle;
  92. ControlHandle    vScrollControl,doneControl,whichControl;
  93. EventRecord        theEvent;
  94. int                cntlCode,controlVal,oldVal,height;
  95. char            theChar;
  96.  
  97.  
  98.     GetPort(&oldPort);
  99.     
  100.     if (!(helpWPtr = GetNewWindow(helpResWIND,NULL,(WindowPtr) -1L)))
  101.         FatalError("\p Can't allocate memory for help window");
  102.     
  103.     SetPort(helpWPtr);
  104.     
  105.     CenterWindow((WindowPtr) helpWPtr);
  106.     ShowWindow((WindowPtr) helpWPtr);
  107.     
  108.     TextFont(geneva);
  109.     TextSize(10);
  110.     TextFace(0);
  111.     
  112.     SetRect(&viewRect,helpWPtr->portRect.left,helpWPtr->portRect.top,helpWPtr->portRect.right-15,helpWPtr->portRect.bottom-35);
  113.     InsetRect(&viewRect,5,5);
  114.     destRect = viewRect;
  115.     
  116.     
  117.     if (!(helpTEH = TEStylNew(&destRect,&viewRect)))
  118.         FatalError("\p Can't allocate memory for help text record");
  119.     
  120.     (**helpTEH).lineHeight = -1;
  121.     (**helpTEH).fontAscent = -1;
  122.     
  123.     InsetRect(&viewRect,-5,-5);
  124.     FrameRect(&viewRect);
  125.     
  126.     SetRect(&vScrollRect,viewRect.right-1,viewRect.top,helpWPtr->portRect.right,viewRect.bottom);
  127.     vScrollControl = NewControl(helpWPtr,&vScrollRect,"\p",TRUE,1,1,1,scrollBarProc,(long) helpTEH);
  128.     SetRect(&vScrollRect,viewRect.right-1,viewRect.top+16,helpWPtr->portRect.right,viewRect.bottom-16);
  129.     
  130.     SetRect(&doneRect,helpWPtr->portRect.right-55,helpWPtr->portRect.bottom-25,helpWPtr->portRect.right-5,helpWPtr->portRect.bottom-5);
  131.     doneControl = NewControl(helpWPtr,&doneRect,"\pDone",TRUE,0,0,1,pushButProc,0L);
  132.     
  133.     PenNormal();
  134.     PenSize(3,3);
  135.     InsetRect(&doneRect,-4,-4);
  136.     FrameRoundRect(&doneRect,16,16);
  137.     InsetRect(&doneRect,4,4);
  138.     PenSize(1,1);
  139.     
  140.     helpText = GetResource('TEXT',helpResTEXT);
  141.     helpStyle = GetResource('styl',helpResSTYL);
  142.     
  143.     if (!helpText || !helpStyle)
  144.         ErrorAlert("\p Can't access help 'TEXT' and 'STYL' resources");
  145.     
  146.     else
  147.     {
  148.         HLock(helpText);
  149.         
  150.         TEStylInsert(StripAddress(*helpText),SizeResource(helpText),helpStyle,helpTEH);
  151.         
  152.         HUnlock(helpText);
  153.         ReleaseResource(helpText);
  154.         ReleaseResource(helpStyle);
  155.         
  156.         
  157.         oldVal = (**helpTEH).nLines;
  158.         controlVal = 1;
  159.         height = (**helpTEH).viewRect.bottom - (**helpTEH).viewRect.top;
  160.         
  161.         while (oldVal-controlVal>1 && TEGetHeight(oldVal-controlVal,oldVal-1,helpTEH)<height)
  162.             controlVal++;
  163.         
  164.         if (controlVal>1  && TEGetHeight(oldVal-controlVal,oldVal-1,helpTEH)>height)
  165.             controlVal--;
  166.         
  167.         SetCtlMax(vScrollControl,oldVal-controlVal);
  168.         
  169.         BeginUpdate(helpWPtr);
  170.         EndUpdate(helpWPtr);
  171.         
  172.         do
  173.         {
  174.             SystemTask();
  175.             
  176.             cntlCode = 0;
  177.             
  178.             if (GetNextEvent(everyEvent,&theEvent))
  179.             {
  180.                 if (theEvent.what == mouseDown)
  181.                 {
  182.                     GlobalToLocal(&theEvent.where);
  183.                     
  184.                     cntlCode = FindControl(theEvent.where,helpWPtr,&whichControl);
  185.                     
  186.                     if (cntlCode != 0)
  187.                     {
  188.                         if (whichControl == vScrollControl)
  189.                         {
  190.                             if (cntlCode == inThumb)
  191.                             {
  192.                                 oldVal = GetCtlValue(vScrollControl);
  193.                                 
  194.                                 TrackControl(vScrollControl,theEvent.where,NULL);
  195.                                 
  196.                                 controlVal = GetCtlValue(vScrollControl);
  197.                                 
  198.                                 if (controlVal > oldVal)
  199.                                     TEScroll(0,-TEGetHeight(oldVal,controlVal-1,helpTEH),helpTEH);
  200.                                     
  201.                                 else if (controlVal < oldVal)
  202.                                     TEScroll(0,TEGetHeight(controlVal,oldVal-1,helpTEH),helpTEH);
  203.                             }
  204.                             
  205.                             else
  206.                                 TrackControl(vScrollControl,theEvent.where,HelpScrollProc);
  207.                         }
  208.                         
  209.                         else if (whichControl == doneControl)
  210.                             cntlCode = TrackControl(doneControl,theEvent.where,NULL);
  211.                         
  212.                         else
  213.                             SysBeep(1);
  214.                     }
  215.                     else
  216.                         SysBeep(1);
  217.                 }
  218.                 
  219.                 else if (theEvent.what==keyDown || theEvent.what==autoKey)
  220.                 {
  221.                     theChar = theEvent.message & charCodeMask;
  222.                     
  223.                     if (theChar == (char) 0x0d || theChar == (char) 0x03)
  224.                         cntlCode = inButton;
  225.                 }
  226.                 
  227.                 else if (theEvent.what==updateEvt && (WindowPtr) theEvent.message==helpWPtr)
  228.                 {
  229.                     BeginUpdate(helpWPtr);
  230.                     
  231.                     DrawControls(helpWPtr);
  232.                     
  233.                     if (FrontWindow() != helpWPtr)
  234.                         EraseRect(&vScrollRect);
  235.                     else
  236.                     {
  237.                         PenNormal();
  238.                         PenSize(3,3);
  239.                         InsetRect(&doneRect,-4,-4);
  240.                         FrameRoundRect(&doneRect,16,16);
  241.                         InsetRect(&doneRect,4,4);
  242.                         PenSize(1,1);
  243.                     }
  244.                     
  245.                     TEUpdate(&viewRect,helpTEH);
  246.                     FrameRect(&viewRect);
  247.                     
  248.                     EndUpdate(helpWPtr);
  249.                 }
  250.                 
  251.                 else if (theEvent.message==activateEvt && (WindowPtr) theEvent.message==helpWPtr) 
  252.                 {
  253.                     if (theEvent.modifiers & activeFlag) 
  254.                     {
  255.                         TEActivate(helpTEH);
  256.                         HiliteControl(doneControl,0);
  257.                         
  258.                         PenNormal();
  259.                         PenSize(3,3);
  260.                         InsetRect(&doneRect,-4,-4);
  261.                         FrameRoundRect(&doneRect,16,16);
  262.                         InsetRect(&doneRect,4,4);
  263.                     }
  264.                     else 
  265.                     {
  266.                         TEDeactivate(helpTEH);
  267.                         EraseRect(&vScrollRect);
  268.                         
  269.                         HiliteControl(doneControl,255);
  270.                         PenNormal();
  271.                         PenSize(3,3);
  272.                         PenPat(white);
  273.                         InsetRect(&doneRect,-4,-4);
  274.                         FrameRoundRect(&doneRect,16,16);
  275.                         InsetRect(&doneRect,4,4);
  276.                     }
  277.                 }
  278.             }
  279.         
  280.         } while (cntlCode != inButton);
  281.     }
  282.     
  283.     TEDispose(helpTEH);
  284.     KillControls(helpWPtr);
  285.     DisposeWindow(helpWPtr);
  286.     
  287.     SetPort(oldPort);
  288. }